import pandas as pd
dataset_path=tf.keras.utils.get_file("auto-mpg.data", ("http://archive.ics.uci.edu/ml/machine-learning-databases/auto-mpg/auto-mpg.data"))
column_names=['MPG', 'Cylinders', 'Displacement', 'Horsepower', 'Weight', 'Acceleration', 'ModelYear', 'Origin']
df=pd.read_csv(dataset_path, names=column_names, na_values='?', comment='\t', sep=' ', skipinitialspace=True)
df=df.dropna()
df=df.reset_index(drop=True)
import sklearn
import sklearn.model_selection
df_train, df_test=sklearn.model_selection.train_test_split(df, train_size=0.8)
train_stats=df_train.describe().transpose()
numeric_column_names=[
'Cylinders', 'Displacement', 'Horsepower', 'Weight', 'Acceleration']
df_train_norm, df_test_norm=df_train.copy(), df_test.copy()
for col_name in numeric_column_names:
mean=train_stats.loc[col_name, 'mean']
std=train_stats.loc[col_name, 'std']
df_train_norm.loc[:, col_name]=(df_train_norm.loc[: ,col_name]-mean)/std
df_test_norm.loc[:, col_name]=(df_train_norm.loc[: ,col_name]-mean)/std